<?php
class Admin_Form_AddProductCategory extends Apps_Form {
	public function init() {
	    $dataMaper 	= new Model_Tool_DataMapper();

        $id = Zend_Controller_Front::getInstance()->getRequest()->getParam('id');

	    $tbCategory = new Model_DbTable_ProductCategory();
        if($id) {
    	    $select = $tbCategory->fetchAll(array('parent_id =?' => 0, 'status =?' => $tbCategory::STATUS_ACTIVE , 'id !=?' => $id));
        } else {
    	    $select = $tbCategory->fetchAll(array('parent_id =?' => 0, 'status =?' => $tbCategory::STATUS_ACTIVE));
        }

	    $parentCategory = new Zend_Form_Element_Select(
	            'parent_id',
	            array('label'        => 'Parent Category',
                      'multiOptions' => $dataMaper->mapKeyValue(
                            $select,
                            'id',
                            'title',
                            array('0' => 'Parent Category')
                      )
	            ));

		$title = new Zend_Form_Element_Text(
				'title',
				array('label' 	 => 'Title',
				      'required' => true));
		$title->addValidator(new Zend_Validate_NotEmpty());

		$status = new Zend_Form_Element_Select(
		        'status',
		        array('label'      => 'Public',
		              'multiOptions' => array(1 => 'Yes', 0 => 'No')));

		$sortingNumber = new Zend_Form_Element_Text(
		        'sorting_number',
		        array('label'      => 'Sorting Number',
		              'class'      => 'input-mini'));

		$metaKeyWord = new Zend_Form_Element_Textarea(
		        'meta_keyword',
		        array('label' 		=> 'Meta Keyword',
					  'rows'	=> 5,
					  'cols'	=> 80));

		$metaDescription = new Zend_Form_Element_Textarea(
		        'meta_description',
		        array('label' 		=> 'Meta Description',
					  'rows'	=> 5,
					  'cols'	=> 80));
		$headerTitle = new Zend_Form_Element_Textarea(
		        'header_title',
		        array('label' 		=> 'Header Title',
					  'rows'	=> 5,
					  'cols'	=> 80));


		$this->addElement($parentCategory)
			 ->addElement($title)
			 ->addElement($status)
			 ->addElement($sortingNumber)
			 ->addElement($metaKeyWord)
			 ->addElement($metaDescription)
			 ->addElement($headerTitle);

		$this->setLegend('Add New Product Category');
		$this->addActionGroup()
			 ->makeup();
	}
}